#!/bin/bash
set -euxo pipefail

# The Git Root WorkSpace
WORKSPACE=$(echo $PWD/../)
CURRENT_WORKDIR=$PWD

# Move the Main File to Git Root WorkSpace
cp $WORKSPACE/cmd/api/main.go $WORKSPACE

go env -w GOPROXY="https://goproxy.cn,direct"
cd $WORKSPACE && go mod download

# Build Binary Exec file
cd $WORKSPACE && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o main main.go

# Move binary to Current WorkSpace
rm $WORKSPACE/main.go
mv $WORKSPACE/main $CURRENT_WORKDIR/main